#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__author__ = "Administrator"
__name__="main_server"
__date__="2016/8/15"
__time__="16:16"
"""
import global_settings
from redishelper import RedisHelper
import servialize
import actions_process
class MonitorServer(object):
    def __init__(self,ip,port):
        self.ip = ip
        self.port = port
        self.hosts = servialize.all_host_configs()
        self.redis = RedisHelper()
    def handle(self):
        redis_sub = self.redis.subscribe()
        while True:
            msg = redis_sub.parse_response()
            print 'recv:',msg
            # 死循环，收到消息就交给actions_process处理
            actions_process.action_process(self,msg) # 传递self代表将这个实例传过去，就可以调用实例下的模块和方法-这里讲实例传给了action_process
            print '---waiting for mew msg---'

            for host,val in self.hosts['hosts'].items():
                print host,val
    def run(self):
        print '---starting monitor server---'
        self.handle()
    def process(self):
        pass

if __name__ == '__main__':
    s = MonitorServer('192.168.4.129','6379')
    s.run()


